package com.rongxun.common.widget;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.rongxun.common.R;

import androidx.annotation.NonNull;


/**
 * @author forza
 * @classname: LoadingDialog
 * @Description:
 * @date 2017/5/9 14:04
 */
public class LoadingDialog extends Dialog {
    private Context context;
    private String  msg; //跟随Dialog 一起显示的message 信息！

    public LoadingDialog(@NonNull Context context) {
        super(context);
        this.context = context;
        this.msg = msg;
    }

    public static Dialog createLoadingDialog(Context context, String msg, boolean cancelable) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.dialog_loading, null);// 得到加载view
        ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progressbar);
        progressBar.getIndeterminateDrawable()
                .setColorFilter(Color.parseColor("#D8B267"), PorterDuff.Mode.SRC_IN);

        TextView tipTextView = (TextView) view.findViewById(R.id.tv_loading_msg);// 提示文字
        tipTextView.setText(msg);// 设置加载信息

        Dialog loadingDialog = new Dialog(context, R.style.alertView);// 创建自定义样式dialog
        loadingDialog.setCancelable(cancelable);// 不可以用“返回键”取消
        loadingDialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
        loadingDialog.setContentView(view, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT));// 设置布局
        return loadingDialog;
    }
}
